package com.example.xiaomiao.Mapper;

import com.example.xiaomiao.DO.Money_Record;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface MoneyRecordMapper {
    void addMoneyRecords(@Param("id") int userId, @Param("date") LocalDate date, @Param("moneyRecords") List<Double> moneyRecords);

    void deleteMoneyRecords(@Param("ids") List<Integer> moneyRecordIds);

    @Update("update money_record set money = #{moneyRecord.money} where money_id = #{moneyRecord.money_id}")
    void updateMoneyRecord(@Param("moneyRecord") Money_Record moneyRecord);

    @Select("select count(*) from money_record where user_id = #{id} and date >= #{startDate} and date <= #{endDate}")
    int getMoneyRecordNum(@Param("id") int useId, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);

    @Select("select money_id,money,date from money_record where user_id = #{id} and date >= #{startDate} and date <= #{endDate} limit #{count} offset #{start}")
    List<Money_Record> getMoneyRecords(@Param("id") int useId, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate, @Param("start") int start, @Param("count") int count);

    @Select("select money,date from money_record where user_id = #{id} and date >= #{startDate} and date <= #{endDate} limit #{count} offset #{start}")
    List<Money_Record> getMoneyRecords2(@Param("id") int useId, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate, @Param("start") int start, @Param("count") int count);
}
